<template>
  <div class="app">
    <!-- 头部 -->
    <van-nav-bar
      :title="title"
      left-text="返回"
      right-text="按钮"
      left-arrow
      @click-left="clickleft"
      fixed
    />
    <!-- 切换区域 -->
    <router-view></router-view>
    <!-- 底部 -->
    <van-tabbar v-model="active">
      <van-tabbar-item icon="home-o" to="/home"></van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/friends"></van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/cart" badge="6"></van-tabbar-item>
      <van-tabbar-item icon="search" to="/Search"></van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data: () => ({
    active: Number(localStorage.active) || 0,
    title: localStorage.title || 'home'
  }),
  methods: {
    clickleft() {
      console.log('返回上一页')
      this.$router.go(-1)
    }
  },
  watch: {
    '$route.meta'(meta) {
      this.title = meta.title
      this.active = meta.active
      localStorage.title = meta.title
      localStorage.active = meta.active
    }
  }
}
//  lang 设置使用cass或less预编译css
//  scoped设置使用样式模块化，表示该样式只会在当前组件使用不会被其他组件css污染 （添加在style标签后）
//  about 同样设置样式模块怀，添加在需要不被污染的css样式后面
</script>
<style scoped lang='less'>
.app {
  padding-top: 46px;
  padding: 50px;
}
</style>
